async function atom(params) {
	// console.debug || (console.debug = function () { });

	async function get_code(file_name, spaceid) {
		const path = require('path');
		const file_path = path.join(process.cwd(), './daoke/' + spaceid + '/' + file_name + '.js');
		const fs = require('fs');
		if (fs.existsSync(file_path)) {
			const file_cont = fs.readFileSync(file_path, 'utf8');
			return file_cont;
		}
		const query = [{
			"query_mode": 1,
			"spaceid": spaceid,
			"systemid": "11",
			"tablename": "base_js",
			"criteria": {
				"productid": spaceid,
				"file_name": file_name
			},
			"fields": {
				"file_cont": 1,
				"_id": 0
			},
			"page_no": 1,
			"page_size": 1
		}];

		try {
			const result = await send_msg("dbacc.find.intranet", query);
			return result[0]["dataArray"][0]["file_cont"];
		} catch (err) {
			console.error('获取页面渲染js文件失败.filename=', file_name, 'spaceid', spaceid);
			throw err;
		}
	}
	const param = params.param;
	const url = param.url;
	const file_name = url.match(/.*\/(.*?)\.html/)[1];
	const render_code = await get_code(file_name, param.spaceid);
	const feidao_exports = {};
	const fun = new Function('require', 'feidao_exports', 'send_msg', render_code);
	fun(require, feidao_exports, send_msg);
	return await feidao_exports.default(url);
}

exports.spaceid = 'feidao_public';
const params = {
	param: {
		url: 'http://127.0.0.1:8889/projects/daoke/p001.html?a=123',
		spaceid: 'bjfeidao_351'
	}
};

const code = atom.toString();
exports.code = code;
if (require.main === module) {
	const iv = require('../dist/invoke');
	iv.default({ code, params }).then((rc) => {
		console.log(JSON.stringify(rc));
	}, (err) => {
		console.error(err);
	});
}
